package com.eshop.service.Impl;

import com.eshop.dao.UserInfoDao;
import com.eshop.pojo.Pager;
import com.eshop.pojo.UserInfo;
import com.eshop.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoDao userInfoDao;

    @Override
    public List<UserInfo> getValidUser() {
        return userInfoDao.getValidUser();
    }

    @Override
    public UserInfo getUserInfoById(int id) {
        return userInfoDao.getUserInfoById(id);
    }

    @Override
    public List<UserInfo> selectByPage(UserInfo userInfo, Pager pager) { //分页获取客户信息 #
        Map<String, Object> param = new HashMap<>();
        param.put("userInfo",userInfo);
        int recordCount = userInfoDao.count(param);//查询客户总数
        if (recordCount > 0) {
            pager.setRowCount(recordCount);
            param.put("pager",pager);
        }
        return userInfoDao.selectByPage(param);
    }

    @Override
    public Integer count(Map<String, Object> param) {
        return userInfoDao.count(param);
    }

    @Override
    public int updateStatus(String ids, String flag) {
        return userInfoDao.updateStatus(ids, flag);
    }
}
